package artid.com.arttogoa;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import artid.com.arttogoa.R;

import artid.com.arttogoa.keeponrecord.MicroscopicMapSelectKeepActivity;
import artid.com.arttogoa.util.AlertUtils;
import artid.com.arttogoa.util.ToastUtil;
import artid.com.arttogoa.view.HandwritingBoard_View;
import artid.com.arttogoa.view.RotateTextView;

/**
 * 
 * 
 * 项目名称：ArtworkArtA 类名称 ：ElectronicSignature_Activity 类描述 ：电子签名页面 创建人 ：耿卫斌
 * 创建时间：2016-12-21 上午10:40:55
 * 
 */
@SuppressLint("ClickableViewAccessibility")
public class ElectronicSignature_Activity extends BaseActivity implements
		OnClickListener {
	private Context mContext;
	private HandwritingBoard_View mHandwritingBoard_View;
	private RotateTextView hint;
	private TextView clearBtn, fallbackBtn, goBack, submitTv;
	private LinearLayout submitBtn;
	private Animation mAnimation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_electronicsignature);
		initView();
	}

	private void initView() {

		mContext = ElectronicSignature_Activity.this;
		mAnimation = AnimationUtils.loadAnimation(mContext, R.anim.rotate_left);
		mAnimation.setFillAfter(true);
		mHandwritingBoard_View = (HandwritingBoard_View) findViewById(R.id.ElectronicSignature_HandwritingBoard);
		hint = (RotateTextView) findViewById(R.id.ElectronicSignature_hint);
		hint.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					hint.setVisibility(View.GONE);
				}
				return false;
			}
		});
		clearBtn = (TextView) findViewById(R.id.ElectronicSignature_clear);
		clearBtn.setOnClickListener(this);
		clearBtn.setAnimation(mAnimation);
		fallbackBtn = (TextView) findViewById(R.id.ElectronicSignature_fallback);
		fallbackBtn.setOnClickListener(this);
		fallbackBtn.setAnimation(mAnimation);
		goBack = (TextView) findViewById(R.id.ElectronicSignature_goBack);
		goBack.setOnClickListener(this);
		goBack.setAnimation(mAnimation);
		submitTv = (TextView) findViewById(R.id.ElectronicSignature_submitTv);
		submitTv.setAnimation(mAnimation);
		submitBtn = (LinearLayout) findViewById(R.id.ElectronicSignature_submitBtn);
		submitBtn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ElectronicSignature_goBack:
			// 返回上一页
			finish();
			break;
		case R.id.ElectronicSignature_submitBtn:
			// 确定
			if (mHandwritingBoard_View.getSavePath() != 0) {
				AlertUtils.AlertElectronicSignatureDialog(mContext,
						mHandwritingBoard_View.getBitmap(), this
								.getWindowManager().getDefaultDisplay()
								.getWidth(), this);
			} else {
				ToastUtil.toast(mContext, "您还没有签名哦！！");
			}
			break;
		case R.id.ElectronicSignature_clear:
			// 清空
			mHandwritingBoard_View.clear();
			hint.setVisibility(View.VISIBLE);
			break;
		case R.id.ElectronicSignature_fallback:
			// 撤销
			mHandwritingBoard_View.revoke();
			if (mHandwritingBoard_View.getSavePath() == 0) {
				hint.setVisibility(View.VISIBLE);
			}
			break;
		case R.id.pop_menu_electronicsignature_resetBtn:
			// 对话框重置
			AlertUtils.dismiss();
			mHandwritingBoard_View.clear();
			hint.setVisibility(View.VISIBLE);
			break;
		case R.id.pop_menu_electronicsignature_saveBtn:
			// 对话框保存
			AlertUtils.dismiss();
			mHandwritingBoard_View.saveImage();
			Intent intent3 = new Intent(ElectronicSignature_Activity.this,
					MicroscopicMapSelectKeepActivity.class);
			ElectronicSignature_Activity.this.setResult(8, intent3);
			ElectronicSignature_Activity.this.finish();
			break;

		default:
			break;
		}
	}

}
